(in-package :ortho-complex)

;; Base type converters
;;;;;;;;;;;;;;;;;;;;;;;

(defun rectangular->complex (x)
  (complex (complex-rectangular::real-part x)
	   (complex-rectangular::imag-part x)))

(defun square (x)
  (expt x 2))

(defun complex->rectangular (x)
  (complex-rectangular::make-complex
   (realpart x)
   (imagpart x)))

(add-ortho-type 'complex-rectangular
		#'complex->rectangular
		#'rectangular->complex)

;; Function wrappers
;;;;;;;;;;;;;;;;;;;;

(defun add (x y)
  (let ((rect-x (base->type 'complex-rectangular x))
	(rect-y (base->type 'complex-rectangular y)))
    (type->base 'complex-rectangular
		(complex-rectangular::add rect-x rect-y))))